package com.qingsong.controller;

import com.mybatisflex.core.paginate.Page;
import com.qingsong.dto.RoleInsertDTO;
import com.qingsong.dto.RolePageDTO;
import com.qingsong.dto.RoleUpdateDTO;
import com.qingsong.entity.Role;
import com.qingsong.vo.MenuSimpleListVO;
import com.qingsong.vo.RoleSimpleListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qingsong.service.RoleService;
import java.util.List;

/**
 * 角色表 控制层。
 *
 * @author qingsong
 * @since 2024-12-22
 */
@Tag(name = "角色")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Operation(summary = "新增 - 单条", description = "新增一条角色记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody RoleInsertDTO dto) {
        return roleService.insert(dto);
    }

    @Operation(summary = "查询 - 单条", description = "按主键查询一条角色记录")
    @GetMapping("select/{id}")
    public Role select(@PathVariable("id") Long id) {
        return roleService.select(id);
    }

    @Operation(summary = "查询 - 简单列表", description = "查询全部角色记录,仅返回简单信息")
    @GetMapping("simpleList")
    public List<RoleSimpleListVO> simpleList() {
        return roleService.simpleList();
    }

    @Operation(summary = "查询 - 分页", description = "分页查询角色记录")
    @GetMapping("page")
    public Page<Role> page(@Validated RolePageDTO dto) {
        return roleService.page(dto);
    }

    @Operation(summary = "修改 - 单条", description = "按主键修改一条角色记录")
    @PutMapping("update")
    public boolean update(@RequestBody RoleUpdateDTO dto) {
        return roleService.update(dto);
    }

    @Operation(summary = "删除 - 单条", description = "按主键删除一条角色记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return roleService.delete(id);
    }

    @Operation(summary = "删除 - 批量", description = "按主键批量删除角色记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return roleService.deleteBatch(ids);
    }

    @Operation(summary = "查询 - 菜单ID列表", description = "按主键查询指定角色拥有的全部菜单ID列表")
    @GetMapping("listMenuIds/{id}")
    public List<Long> listMenuIds(@PathVariable("id") Long id) {
        return roleService.listMenuIds(id);
    }

    @Operation(summary = "修改 - 菜单ID列表", description = "根据角色修改该角色的菜单")
    @PutMapping("updateMenus")
    public boolean updateMenus(@RequestBody RoleUpdateDTO dto) {
        return roleService.updateMenus(dto);
    }
}
